<?php
class indexMod extends base {
	public function index(){
		echo "";


	}
	/**
	 * excel 导入
	 *
	 * @param string $file
	 * @return array
	 */
	public function import(){
		$excel = $this->_excelToArray('a.xls',$type);
		$db = model('member_field');
		$member_db = model('member');
		foreach($excel as $key => $val){
			$val = $this->_htmlspecialchars($val);
			if ($val[0] && $val[3] && $val[3]!='姓名') {
				
			$member = $member_db->where("username='{$val[0]}'")->find();
			$update['company']=$val[1];
			$update['name']=$val[3];
			$update['company_address']=$val[4];
			$update['phone']=$val[5];
			if($member)
			$db->where("uid=".$member['uid'])->data($update)->update();
			}
			
		}
		echo '导入成功';
	}
		/**
	 * excel读取返回数组
	 *
	 * @param string $file
	 * @return array
	 */
		private function _excelToArray($file,$type){
			require_once CP_PATH.'ext/PHPExcel/IOFactory.php';
			$extend = pathinfo($file);
			$extend = strtolower($extend["extension"]);
			$reader_type = array(
			'xls'=> "Excel5",
			'xlsx'=>"Excel2007",
			);
			/*require_once 'Lib/ORG/Classes/PHPExcel/IOFactory.php';
			$reader = PHPExcel_IOFactory::createReader('Excel2007'); //设置以Excel5格式(Excel97-2003工作簿)
			$PHPExcel = $reader->load("1.xlsx"); // 载入excel文件*/
			$PHPExcel = PHPExcel_IOFactory::load($file);
			$sheet = $PHPExcel->getSheet(0); // 读取第一個工作表
			$highestRow = $sheet->getHighestRow(); // 取得总行数
			$highestColumm = $sheet->getHighestColumn(); // 取得总列数
			//$highestColumm = 'Q';

			/** 循环读取每个单元格的数据 */
			for ($row = 4; $row <= $highestRow; $row++){//行数是以第2行开始
				for ($column = 'A'; $column <= $highestColumm; $column++) {//列数是以A列开始
					$dataset[$row][] = $sheet->getCell($column.$row)->getValue();
					//echo $column.$row.":".$sheet->getCell($column.$row)->getValue()."<br />";
				}
			}
			return $dataset;
		}
	}